<template>
	<view class="all-main">
		<u-loading-page :loading="loadding" loading-mode="semicircle" loading-text="欢迎进入风动社区"></u-loading-page>
		<view v-if="!loadding" class="main">
			<!-- <u-sticky>
				<view class="top">
					<u-subsection :list="orderTypeList" keyName="name" @change="sectionChange" :current="orderTypeIndex"></u-subsection>
				</view>
			</u-sticky> -->
			<view class="lists">
				<view v-if="info.length > 0" v-for="(item, index) in info" :key="index" class="items">
					<view class="title">
						<view class="lefts">
							<text>{{item.nickname}}</text>
							<text v-if="item.mobile">{{item.mobile}}</text>
						</view>
						<view class="rights">
							<text v-if="item.status==1" class="reds">待审核</text>
							<text v-if="item.status==2" class="greens">已审核</text>
							<text v-if="item.status==3" class="blues">已调货</text>
							<text v-if="item.status==4" class="reds">已退货</text>
						</view>
					</view>
					<u-line></u-line>
					<view class="con">
						<text>{{item.name}}</text>
						<text class="nums">*{{item.number}}</text>
					</view>
					<u-line></u-line>
					<view class="bottom">
						<view class="lefts">
							<text>{{item.create_time_text}}</text>
						</view>
						<view class="rights">
							<view v-if="item.status == 1 && customerinfo.is_typs == 4" class="btn blues" @click="checkApply(2, item.id)">
								同意
							</view>
							<view v-if="item.status == 1 && customerinfo.is_typs == 4" class="btn reds" @click="checkApply(0, item.id)">
								取消
							</view>
							<view v-if="item.status == 2 && customerinfo.is_typs == 3" class="btn blues" @click="pathTo(item)">
								领取终端
							</view>
						</view>
					</view>
				</view>
				<u-empty v-if="info.length <= 0" mode="order" icon="../../../static/Empty/data_null.png"></u-empty>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loadding: true,
				customerinfo: {},
				orderTypeList: [{
					id: 1,
					name: '待完成'
				}, {
					id: 2,
					name: '已完成'
				}],
				orderTypeIndex: 0,
				type: 1,
				info: [],
				is_true: true
			}
		},
		onLoad(e) {
			this.customerinfo = uni.getStorageSync('customerinfo');
			this.getData()
		},
		methods: {
			// 获取统计数据
			async getData() {
				const {
					data: res
				} = await this.$myHttp5({
					url: 'v1/getTerminalApplyList',
					data: {
						type: this.type
					},
					header: {
						'token': this.customerinfo.token
					}
				});
				this.loadding = false
				if (res.code == 1) {
					this.info = res.data
				}
			},
			// 切换状态
			sectionChange(index) {
				if (this.type != this.orderTypeList[index].id) {
					this.orderTypeIndex = index
					this.type = this.orderTypeList[index].id
					this.loadding = true
					this.getData()
				}
			},
			// 订单详情
			pathTo(item) {
				uni.navigateTo({
					url: '/pages/customer/terminalOrder/detail?id=' + item.id
				})
			},
			// 审核订单
			checkApply(type, id) {
				var msg = '确定要取消吗？'
				if (type == 2) {
					msg = '确定要同意吗？'
				}
				var that = this
				uni.showModal({
					title: '提示',
					content: msg,
					success: function(res) {
						if (res.confirm) {
							that.checkApplyFun(type, id)
						}
					}
				});
			},
			// 审核订单 - 方法
			async checkApplyFun(type, id) {
				var that = this
				if (this.is_true) {
					this.is_true = false
					uni.showLoading({
						title: '加载中'
					});
					const {
						data: res
					} = await this.$myHttp5({
						url: 'v1/checkApply',
						data: {
							apply_id: id,
							type: type
						},
						header: {
							'token': this.customerinfo.token
						}
					});
					this.is_true = true
					uni.hideLoading()
					uni.showToast({
						title: res.msg,
						icon: "none"
					});
					if (res.code == 1) {
						setTimeout(function() {
							that.getData()
						},1500)
					}
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f3f4f6;
	}
	
	.all-main {
		.main {
			.top {
				padding: 20rpx;
				background-color: #ffffff;
			}
			.lists {
				padding: 20rpx;
				.items {
					background-color: #ffffff;
					margin-bottom: 20rpx;
					border-radius: 16rpx;
					padding: 20rpx 20rpx 0 20rpx;
					.title {
						display: flex;
						justify-content: space-between;
						align-items: center;
						padding-bottom: 20rpx;
						font-size: 32rpx;
						.lefts {
							font-weight: bold;
							text {
								padding-right: 16rpx;
							}
						}
						.rights {
							font-size: 24rpx;
							text {
								color: #ffffff;
								padding: 10rpx 20rpx;
								border-radius: 12rpx;
							}
						}
					}
					.con {
						padding: 20rpx 0;
						font-size: 28rpx;
						display: flex;
						justify-content: space-between;
						.nums {
							font-weight: bold;
						}
					}
					.bottom {
						display: flex;
						justify-content: space-between;
						font-size: 24rpx;
						padding: 20rpx 0;
						align-items: center;
						.lefts {
							color: #c8c9cc;
							font-size: 28rpx;
						}
						.rights {
							display: flex;
							.btn {
								padding: 10rpx 20rpx;
								color: #ffffff;
								border-radius: 12rpx;
								margin-left: 10rpx;
							}
						}
					}
				}
			}
		}
		.reds {
			background-color: #fa3534;
		}
		.blues {
			background-color: #2979ff;
		}
		.greens {
			background-color: #19be6b;
		}
	}
</style>
